#include "ScreenshotHandler.h"
#include "../Game.h"


ScreenshotHandler::ScreenshotHandler(const core::stringc filename) {
	m_Filename = filename;
	m_Number = 0;
}

ScreenshotHandler::~ScreenshotHandler() {
}

bool ScreenshotHandler::OnEvent(const SEvent& event) {
	// check if user presses the key F12
	core::stringc cFilename;
	cFilename.reserve(256);
	if (event.EventType == EET_KEY_INPUT_EVENT &&
		event.KeyInput.Key == KEY_F12 &&
		event.KeyInput.PressedDown == false)
	{
		video::IImage* image = Game::s_Device->getVideoDriver()->createScreenShot();
		if (image) {
			sprintf ((c8*)cFilename.c_str(),"%s_shot%04d.jpg",
						m_Filename.c_str(),
						m_Number++);
			Game::s_Device->getVideoDriver()->writeImageToFile(image, cFilename.c_str(), 85);
			image->drop();
		}
		return true;
	}
	return false;
}
